home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
boe.pres.k12.wv.us
/
boe.pres.k12.wv.us.zip
/
boe.pres.k12.wv.us
/
Utilities
/
Xerox Workcentre 5335
/
Windows Scan
/
64-bit_x64
/
Japanese
/
cpsimage.cab
/
data
/
xipProcs
/
colorseg.proc
< prev
next >
Wrap
Text File
|
2009-04-23
|
3KB
|
90 lines
// Load scripted support procedures
//#load "xipProcs/printLayer.proc";
#load "xipProcs/thresholdRange.proc";
#load "xipProcs/colorMap.proc";
#load "sys/stdlib.elf";
// Dynamically load necessary functions
LoadClasses (filename: "xeng");
private
PROCEDURE XIPColorSeg (XIPIMAGE input, BOOLEAN debug)
RETURNS (XIPIMAGE output)
{
XIPIMAGE imgSRGB, imgHSV, mask;
XIPCOLOR color, bgcolor, maskcolor;
XIPCOLORMAP cmap;
INTEGER i, classid, bgclassid, ncolors;
XIPTIMER timer;
if (debug)
timer.start ();
// Make local copy of input image
imgSRGB = input.Copy ();
// Make certain input image is in proper format
imgSRGB = imgSRGB.interleave (scanline: 1
).convert (to: (8)
).cspace (outspace: "srgb", precise: 1
// Convert reduced input image to HSV color space
).reduce (by: (4, 4), mode: 0
).cspace (outspace: "hsv", precise: 1
);
// Quantize colors of input image
ncolors = cmap.exec (input: imgHSV, method: "diverse", maxcolors: 256);
if (debug)
print "Number of colors found: " + ncolors;
// Reduce to primitive colors
cmap.reduce ();
// Convert colormap to SRGB color space and sort
cmap.changespace (photo: XIP_SRGB_COLOR);
cmap.sort ();
if (debug)
print "Time to get colors: " + timer.elapsed (lap: TRUE);
// Apply colormap to full-sized input image
imgSRGB = cmap.apply (input: imgSRGB);
if (debug)
print "Time to apply colors to image: " + timer.elapsed (lap: TRUE);
// Get background color
bgcolor = cmap.entries[cmap.nentries-1];
bgclassid = XIPColorClass (color: bgcolor);
// Add background layer to output image
output = pattern (constant: bgcolor.c, space: "srgb",
size: (imgSRGB.imageWidth, imgSRGB.imageHeight)).exec ();
output.setMember (member: "color", num: 0, value: bgcolor);
if (debug)
print "Time to add background layer: " + timer.elapsed (lap: TRUE);
// Add color mask to output image for each "visible" color in colormap
for (i=0; i<cmap.nentries-1; i++) {
maskcolor = cmap.entries[i];
classid = XIPColorClass (color: maskcolor);
mask = XIPThresholdRange (src: imgSRGB, minLevels: maskcolor.c,
maxLevels: maskcolor.c, mode: 2);
mask = mask.convert (to: (1)).exec ();
output = output.addLayer (image: mask, lindex: 0, color: maskcolor);
if (debug)
print "Time to create & add mask layer " + (i+1) + ": "
+ timer.elapsed (lap: TRUE);
}
if (debug)
print "Time to segment image: " + timer.elapsed ();
}